import { defineStore } from 'pinia'
import { queryStatusDictionaryList } from '@/api/api'
import { groupBy } from 'lodash'

export const statusmark = defineStore('statusmark', {
  state: () => ({
    g_statusmark: {},
  }),
  actions: {
    // 获取所有类别
    async listFn() {
      this.g_statusmark = sessionStorage.getItem('g_statusmark')
        ? JSON.parse(sessionStorage.getItem('g_statusmark'))
        : []
      let { data } = await queryStatusDictionaryList()
      let res = groupBy(data, 'statusmark')
      sessionStorage.setItem('g_statusmark', JSON.stringify(res))

      this.g_statusmark = res
      return Promise.resolve(res)
    },
  },
})
